import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Hot from '../views/Hot/Hot.vue';
import Set from "../views/Set/EditData/EditData.vue";
import AboutHome from "../views/About/HomeMy/HomeMy.vue";
import Home from "../views/Home/Home.vue";
const routes: Array<RouteRecordRaw> = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '',
        component: () => import(/* webpackChunkName: "home" */  '../views/Home/BlogNew/BlogNew.vue')
      },
      {
        path: 'FocusMy',
        component: () => import(/* webpackChunkName: "home" */ '../views/Home/FocusMy/FocusMy.vue')
      }
    ]

  },
  {
    path: '/TV',
    name: 'TV',
    component: () => import(/* webpackChunkName: "tv" */ '../views/Tv.vue'),
  },
  {
    path: '/Hot',
    name: 'Hot',
    alias: "/",
    component: Hot,
    children: [
      {
        // 当 /user/:id/profile 匹配成功
        // UserProfile 将被渲染到 User 的 <router-view> 内部
        path: '',
        component: () => import(/* webpackChunkName: "hot" */ '../views/Hot/hotBlog/hotBlog.vue'),
      },
      {
        // 当 /user/:id/profile 匹配成功
        // UserProfile 将被渲染到 User 的 <router-view> 内部
        path: 'newBlog',
        component: () => import(/* webpackChunkName: "hot" */ '../views/Hot/hotSearch/hotSearch.vue'),
      },
      {
        // 当 /user/:id/profile 匹配成功
        // UserProfile 将被渲染到 User 的 <router-view> 内部
        path: 'searchBlog',
        component: () => import(/* webpackChunkName: "hot" */ '../views/Hot/searchBlog/searchBlog.vue'),
      },
      {
        // 当 /user/:id/profile 匹配成功
        // UserProfile 将被渲染到 User 的 <router-view> 内部
        path: 'searchBlog/:id',
        component: () => import(/* webpackChunkName: "hot" */ '../views/Hot/searchBlog/searchBlogById/searchBlogById.vue'),
      },
    ]
  },
  {
    path: '/Email',
    name: 'Email',
    component: () => import(/* webpackChunkName: "Email" */ '../views/Email.vue'),
  },
  {
    path: '/about/:id',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About/About.vue'),
    children: [
      {
        path: "",
        component: AboutHome
      },
      {
        path: "FocusMy",
        component: () => import(/* webpackChunkName: "about" */ '@/views/About/FocusMy/FocusMy.vue')
      }
      ,
      {
        path: "FansMy",
        component: () => import(/* webpackChunkName: "about" */ '@/views/About/FansMy/FansMy.vue')
      }
      ,
      {
        path: "CollectionMy",
        component: () => import(/* webpackChunkName: "about" */ '@/views/About/CollectionMy/CollectionMy.vue')
      }
      ,
      {
        path: "LikeMy",
        component: () => import(/* webpackChunkName: "about" */ '@/views/About/LikeMy/LikeMy.vue')
      }
    ]
  },
  {
    path: '/Set',
    name: 'Set',
    component: Set,
    beforeEnter(to, from) {
      // console.log(to, from);
    },
    children: [
      {
        path: '',
        component: Set,
      },
      {
        path: 'AccountSecurity',
        component: () => import(/* webpackChunkName: "set" */ '../views/Set/AccountSecurity/AccountSecurity.vue'),
      },
      {
        path: 'Privacy',
        component: () => import(/* webpackChunkName: "set" */ '../views/Set/Privacy/Privacy.vue'),
      },
      {
        path: 'Message',
        component: () => import(/* webpackChunkName: "set" */ '../views/Set/Message/Message.vue'),
      },
      {
        path: 'Shielding',
        component: () => import(/* webpackChunkName: "set" */ '../views/Set/Shielding/Shielding.vue'),
      },
      {
        path: 'Preferences',
        component: () => import(/* webpackChunkName: "set" */ '../views/Set/Preferences/Preferences.vue'),
      },
    ]
  },
  {
    path: '/:pathMatch(.*)',
    component: Hot,
    beforeEnter(to, from, next) {
      next("/Hot");
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 全局路由拦截
router.beforeEach(async (to, from) => {
  if (!localStorage.getItem("token") && to.fullPath.indexOf('/Hot') == -1) {
    return { path: '/Hot' }
  }
})

export default router
